﻿CREATE PROCEDURE [dbo].[proc_Order_Getlist_my_Wage]
	(
		@UserName nvarchar(50),
		@CusName nvarchar(50),
		@StartDate nvarchar(10),
		@EndDate nvarchar(50)
	)
AS
begin
	;WITH list As(Select ROW_NUMBER() OVER (ORDER BY StateId DESC,TradeDate DESC)AS Row
		,Id
		,OId
		,CusName
		,TypeName
		,Salesman
		,SalesmanAccount
		,TradeDate
		,CreateDate
		,IsNull(YingShouPrice,0) As YingShouPrice
		,IsNull(ShiShouPrice,0) As ShiShouPrice
		,IsNULL((Select Title From Order_State Where Id=[Order].StateId),'---') As StateName
		From [Order]
		Where SalesmanAccount=@UserName and (Convert(nchar(10),TradeDate,120) between @StartDate and @EndDate) and (@CusName='' Or CusName like '%'+@CusName+'%')
		and not exists(Select 1 From Employee_Wage_TiCheng Where OId=[Order].OId and Consignee=[Order].SalesmanAccount)
	)
	
	Select * From list
end
	RETURN
